<style lang="scss" scoped>
#medicineList{
    background:#fff;
    padding:10px;
    .me-list{
        min-height:300px;
         _height:300px;
        .m-list-content{
            margin:10px 0;
            .m-list-title{
                line-height:40px;
                font-size:18px;
                font-weight:700;
                color:#666;
                cursor: pointer;
            }
            .m-list-des{
                line-height:25px;
                color:#999;
            }
        }
    }
}
</style>
<template>
    <div id="medicineList" class="content-mask" v-loading="loading">
        <el-card class="me-list" v-if="resultList.length>0">
            <dl v-for="(item,index) in resultList" :key="index" class="m-list-content">
                <dt @click="goBasic(item.id)" class="m-list-title">{{item.name}}</dt>
                <dd class="m-list-des">{{item.totalname}}</dd>
            </dl>
        </el-card>
        <el-card class="me-list" v-else>
            搜索结果为空，请重新搜索！
        </el-card>
    </div>
</template>
<script>
import {medicine} from 'api/index.js';
export default {
    name: 'medicineList',//药物列表
    data(){
        return{
            searchStr:"",
            loading:false,
            resultList:[]
        }
    },
    methods:{
        getSearchList(){
            var obj={
                str:this.searchStr,
            }
            this.loading = true;
            medicine.drugSolrSerachAll(obj).then((data)=>{
                if(data.status == 200){
                    if(data.data && data.data.length>0){
                        this.resultList = data.data;
                    }else{
                        this.resultList = [];
                    }
                }else{
                    this.resultList = [];
                    this.$message.error(data.msg);
                }
                this.loading = false;
            }).catch((error)=>{
                this.resultList = [];
                this.loading = false;
            })
        },
        //跳转至药物基本信息
        goBasic(id){
            this.$store.state.searchType = 1;
            this.$store.state.searchId = id;
            this.$router.push("/basic");
        }
    },
    created(){
        this.searchStr = this.$store.state.searchStr;
        this.getSearchList();
    },
    watch:{
        "$store.state.searchStr":function(){
            if(this.searchStr != this.$store.state.searchStr){
                this.searchStr = this.$store.state.searchStr;
            }
        }
    }
}
</script>